#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int n, m, id;
struct cube {
  int x, y, h;
  bool operator>(const cube& b) const {
    return (x > b.x && y > b.y) || (x > b.y && y > b.x);
  }
} c[N];
int dp[N];
int get(int id) {
  int& ans = dp[id];
  if (ans > 0) return ans;
  ans = c[id].h;
  for (int i = 1; i <= m; ++i) {
    if (c[id] > c[i]) {
      ans = max(ans, get(i) + c[id].h);
    }
  }
  return ans;
}
int main() {
  int tc = 0;
  while (cin >> n && n) {
    memset(dp, 0, sizeof(dp));
    m = n * 3;
    for (int i = 1; i <= m; i += 3) {
      int x, y, h;
      cin >> x >> y >> h;
      c[i] = {x, y, h};
      c[i + 1] = {h, x, y};
      c[i + 2] = {y, h, x};
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
      ans = max(get(i), ans);
    }
    printf("Case %d: maximum height = %d\n", ++tc, ans);
  }
}
